<template>
  <Modal
    title="申请页面"
    :value="value"
    :mask-closable="true"
    :footer-hide="true"
    @input="$emit('input', $event)"
  >
    <Form
      ref="formLkyApplyAdminPass"
      :model="formLkyApplyAdminPass"
      :rules="ruleValidate"
      label-position="right"
      :label-width="80"
    >

      <FormItem label="表名" prop="name">
        <Input type="text" v-model="formLkyApplyAdminPass.file_name" placeholder="表名" readonly/>
      </FormItem>
      <FormItem label="申请理由" prop="remark_info">
        <Input type="text" v-model="formLkyApplyAdminPass.remark_info"  placeholder="申请理由"readonly/>
      </FormItem>
      <FormItem>
        <!-- <Button type="primary" @click="handleSubmit('formLkyApply')">提交</Button> -->
        <!-- <Button @click="handleReset('formLkyClass')" style="margin-left: 8px">重置</Button> -->
      </FormItem>

    </Form>
  </Modal>
</template>
<script>
import { save } from '@/api/lky/lkyApply'
import { createModelObj, coverProps, coverFormProps } from '@/libs/util'
// 学院查询、专业查询
import { queryAll } from '@/api/lky/lkyCollege'
import { queryAllM } from '@/api/lky/lkyMajor'

export default {
  name: 'Add',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    LkyApplyAdminPass: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      collegeList: [],
      coid: '',
      majorList: [],
      formLkyApplyAdminPass: {
        fife_name: '',
        remark_info: '',
        times: '',
        count: '',
        start_time: '',
        end_time: '',
				remark_info:'',
      },
	  lkyApply :{
		  remark_info: ''
		  },
	  
      ruleValidate: {

        // file_name: [
        //   { required: true, message: '该值不能为空', trigger: 'blur' },
        //   { type: 'string', max: 20, message: '长度最长为20', trigger: 'blur' }
        // ],
        // remark_info: [
        //   { required: false, message: '该值不能为空', trigger: 'blur' },
        //   { type: 'string', max: 20, message: '长度最长为20', trigger: 'blur' }
        // ]
      }
    }
  },
  methods: {
    onOpenChangeCollege () {
      queryAll().then(res => {
        this.collegeList = res.data
        this.formLkyApplyAdminPass.mid = ''
      })
    },
    onOpenChangeMajor (coid) {
      queryAllM({ 'coid': this.coid }).then(res => {
        this.majorList = JSON.parse(JSON.stringify(res.data))
      })
    },
    handleSubmit (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          save(Object.assign({}, createModelObj(this.lkyApply, 'lkyApplyRecord'))).then(
            res => {
              if (res) {
                this.$emit('addRow', res.row)
                this.$emit('input', false)
                this.handleReset(name)
              }
            }
          )
        } else {
          this.$Message.error('验证失败!')
		  alert(formLkyApply.remark_info)
        }
      })
    },
    handleReset (name) {
      this.coid = ''
      this.formLkyApplyAdminPass.mid = ''
      this.$refs[name].resetFields()
    }
  },
  watch: {
    value: function (val, oldVal) {
      this.$refs.formLkyApplyAdminPass.resetFields()
      coverFormProps(this.formLkyApplyAdminPass, this.LkyApplyAdminPass)
    },
   
    LkyApplyAdminPass (n) {
      if (n != null) {
		  console.log('========')
		  console.log(n)
		  this.formLkyApplyAdminPass = n
        this.coid = n.id2
        // this.formLkyClass.mid = n.mid
        this.onOpenChangeMajor()
      }
    }
  },
  // 这里
  mounted () {
    this.onOpenChangeCollege()
    this.onOpenChangeMajor()
  }
}
</script>
